﻿//-------------------------------------------------------------------
//版权所有：版权所有(C) 2010， YIBO(China) Studio 
//系统名称：验证控件
//文件名称：ClientValidatorCollection.cs
//模块名称：验证控件
//模块编号：
//作　　者：LHC
//完成日期：2010/8/29 14:34:00
//功能说明：
//-----------------------------------------------------------------
//修改记录：
//修改人：  
//修改时间：
//修改内容：
//-------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;

namespace MvcMall.Framework.FormValidator
{
 
    /// <summary>
    /// 验证控件集合
    /// </summary>
    public class ClientValidatorCollection : ICollection, IEnumerable
    {
        #region//////// 属性 ////////
        /// <summary>
        /// 验证控件
        /// </summary>
        private ValidateTarget owner;
        /// <summary>
        /// 验证集合
        /// </summary>
        private ArrayList validators;

        #endregion

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="owner">验证控件</param>
        /// <param name="validators">集合对象</param>
        public ClientValidatorCollection(ValidateTarget owner, ArrayList validators)
        {
            this.owner = owner;
            this.validators = validators;
        }

        /// <summary>
        /// 追加验证
        /// </summary>
        /// <param name="validator">验证对象</param>
        public void Add(ClientValidator validator)
        {
            this.AddAt(-1, validator);
        }

        /// <summary>
        /// 添加到指定索引验证
        /// </summary>
        /// <param name="index">集合索引</param>
        /// <param name="validator">验证对象</param>
        public void AddAt(int index, ClientValidator validator)
        {
            if (validator == null)
            {
                throw new ArgumentNullException("validator");
            }
            if (index == -1)
            {
                this.validators.Add(validator);
            }
            else
            {
                this.validators.Insert(index, validator);
            }
            validator.SetOwner(this.owner);
        }

        /// <summary>
        /// 复制验证
        /// </summary>
        /// <param name="array">集合对象</param>
        /// <param name="index">集合索引</param>
        public void CopyTo(Array array, int index)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            IEnumerator enumerator = this.GetEnumerator();
            while (enumerator.MoveNext())
            {
                array.SetValue(enumerator.Current, index++);
            }
        }

        /// <summary>
        /// 获取集合
        /// </summary>
        /// <returns></returns>
        public IEnumerator GetEnumerator()
        {
            return this.validators.GetEnumerator();
        }

        public int IndexOf(ClientValidator validator)
        {
            if (validator != null)
            {
                return this.validators.IndexOf(validator);
            }
            return -1;
        }

        public void Remove(ClientValidator validator)
        {
            int index = this.IndexOf(validator);
            if (index >= 0)
            {
                this.RemoveAt(index);
            }
        }

        public void RemoveAt(int index)
        {
            if ((index < 0) || (index >= this.Count))
            {
                throw new ArgumentOutOfRangeException("index");
            }
            this.validators.RemoveAt(index);
        }

        [Browsable(false)]
        public int Count
        {
            get
            {
                return this.validators.Count;
            }
        }

        [Browsable(false)]
        public bool IsSynchronized
        {
            get
            {
                return false;
            }
        }

        [Browsable(false)]
        public ClientValidator this[int index]
        {
            get
            {
                return (ClientValidator) this.validators[index];
            }
        }

        [Browsable(false)]
        public object SyncRoot
        {
            get
            {
                return this;
            }
        }
    }
}



